{
 "metadata": {
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.1"
  },
  "orig_nbformat": 4,
  "kernelspec": {
   "name": "python3",
   "display_name": "Python 3.7.1 64-bit ('Python3_7_2')"
  },
  "interpreter": {
   "hash": "ceed3ede7d2ae4746b1bde0ed48f83d28ba93d0b68e140a25bb2fbb7cbabeb22"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2,
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from tensorflow.keras.preprocessing.text import Tokenizer"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "sentence = ['Attribute From Parameters SOP will now gain proper dependencies on multiparms when in Flatten Multiparm mode',\n",
    "'The Houdini proxy meshes now supports calculating normals if the output mesh from the HDA did not provide any',\n",
    "'This fixes render differences with the refined Static Mesh',\n",
    "'Fixed the Houdini icon displayed above Houdini ProxyMeshes not always being placed properly',\n",
    "'Public API: The various Set*ParameterValue functions now return false only if an error occurs or an invalid value is given',\n",
    "'Previously the functions also returned false if the parameter already had the new value, which was not the expected behaviour',\n",
    "'Fixed bug where hou.Geometry.edgeLoop() did not accept a list consisting of a single edge when the full_loop_per_edge argument was set to true',\n",
    "'Fixed issue with multiparms displaying incorrectly when the first instance starts at 0',\n",
    "'Fixed crash when turning payload loading on or off on a scene with instancing of payloaded assets',\n",
    "'Fixed an issue with batch work items with failed dependencies being left in a waiting state, instead of cleanly failing']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "t = Tokenizer()\n",
    "t.fit_on_texts(sentence)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "lines1 = t.texts_to_sequences(sentence)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "my_sentence = ['when failed at being set to false']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "lines2 = t.texts_to_sequences(my_sentence)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "[[4, 114, 100, 19, 20, 93, 22]]"
      ]
     },
     "metadata": {},
     "execution_count": 9
    }
   ],
   "source": [
    "lines2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "word_index = t.word_index"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "['when', 'failed', 'at', 'being', 'set', 'to', 'false']"
      ]
     },
     "metadata": {},
     "execution_count": 12
    }
   ],
   "source": [
    "my_s = my_sentence[0]\n",
    "ss_list = my_s.split(' ')\n",
    "ss_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "[4, 114, 100, 19, 20, 93, 22]\n"
     ]
    }
   ],
   "source": [
    "ss_index_list = []\n",
    "for i in ss_list:\n",
    "    index = word_index.get(i,'没有')\n",
    "    ss_index_list.append(index)\n",
    "print(ss_index_list)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ]
}